﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace 实验三
{
    public partial class _3_3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext data = new DataClasses1DataContext();
            var x = from s in data.Student
                     where System.Data.Linq.SqlClient.SqlMethods.Like(s.name, String.Format("%{0}%", TextBox1.Text))
                     where s.sex == Convert.ToChar(DropDownList1.SelectedValue)
                     select s;
            GridView1.DataSource = x;
            GridView1.DataBind();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext data = new DataClasses1DataContext();
            Student s = new Student();
            s.name = TextBox2.Text;
            s.sex = Convert.ToChar(TextBox3.Text);
            s.id = TextBox4.Text;
            s.cid = "0";
            data.Student.InsertOnSubmit(s);
            data.SubmitChanges();
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext data = new DataClasses1DataContext();
            var a = from s in data.Student
                      where s.id == TextBox5.Text
                      select s;
            data.Student.DeleteAllOnSubmit(a);
           data.SubmitChanges();

        }
    }
}